#ifndef _LYJ_LOG_H_INCLUDED_
#define _LYJ_LOG_H_INCLUDED_

#include <time.h>
#include "lyj_config.h"
#ifdef _DEBUG 
#define LYJ_LOG 1
#endif
#if LYJ_FLUSH_LOG
#define FLUSH_LOG fflush(stdout)
#else
#define FLUSH_LOG
#endif
#ifdef _WIN32
#define lyj_gettid() ((lyj_uint64_t)GetCurrentThreadId())
#define lyj_getpid() ((lyj_uint64_t)0)
#else
#include <pthread.h>
#define lyj_gettid() ((lyj_uint64_t)pthread_self())
#define lyj_getpid() ((lyj_uint64_t)getpid())
#endif

#ifdef __GNUC__
#define lyj_real_log(fmt, args...)  printf("%u %s(%d): " fmt "\n", (lyj_uint32_t)time(NULL), __func__,__LINE__,  ##args); FLUSH_LOG
#define lyj_real_wlog(fmt, args...)  wprintf(L"%u %ls(%d): " fmt L"\n", (lyj_uint32_t)time(NULL), __FUNCTIONW__,__LINE__,  ##args); FLUSH_LOG
#else
#define lyj_real_log(fmt, ...) printf("%u (%llu) %s(%d): " fmt "\n",(lyj_uint32_t)time(NULL), lyj_gettid(), __func__, __LINE__,  __VA_ARGS__); FLUSH_LOG
#define lyj_real_wlog(fmt, ...) wprintf(L"%u (%llu) %ls(%d): " fmt L"\n", (lyj_uint32_t)time(NULL), lyj_gettid(), __FUNCTIONW__, __LINE__,  __VA_ARGS__); FLUSH_LOG
#endif

#if LYJ_LOG
#define lyj_log lyj_real_log
#define lyj_wlog lyj_real_wlog
#else
#define lyj_log(...)
#define lyj_wlog(...)
#endif


#endif /* _LYJ_LOG_H_INCLUDED_ */
